package com.mapull.example.section1;

import java.util.Arrays;

/**
 * StringSplit 字符串拆分
 *
 * @author mapull
 * @date 2021-09-03
 * @since 1.0
 **/
public class StringSplit {

    public static void main(String[] args) {
        String sentence = "Welcome to mapull website";
        String[] words = sentence.split("\\s", 3); //
        System.out.println(Arrays.toString(words));// [Welcome, to, mapull website]
    }

    public static void main6(String[] args) {
        String sentence = "I-love-you.You love me.";
        String[] words = sentence.split("-|\\s|\\."); //
        System.out.println(Arrays.toString(words));// [I, love, you, You, love, me]
    }

    public static void main5(String[] args) {
        String sentence = "How are you";
        String[] words = sentence.split(" "); // 这里是空格
        System.out.println(Arrays.toString(words));// [How, are, you]

        String[] words2 = sentence.split("\\s"); // 这里是空格的正则表达式
        System.out.println(Arrays.toString(words2));// [How, are, you]
    }

    public static void main4(String[] args) {
        String sentence = "枯藤，老树，昏鸦";
        String[] words = sentence.split("，"); // 这里用分文逗号
        System.out.println(Arrays.toString(words));// [枯藤, 老树, 昏鸦]
    }

    public static void main3(String[] args) {
        String sentence = "Are-you-ok";
        String[] words = sentence.split(null);
    }
    public static void main2(String[] args) {
        String sentence = "Are-you-ok";
    //    String[] words = sentence.split("[");
    }
    public static void main1(String[] args) {
        String sentence = "Are-you-ok";
        String[] words = sentence.split("-");
        System.out.println(words); // [Ljava.lang.String;@1b6d3586
        System.out.println(Arrays.toString(words));// [Are, you, ok]
    }
}
